package com.leyou.item.mapper;

import com.leyou.common.mapper.BaseMapper;
import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * description: 品牌通用Mapper
 * @author 朱正磊
 * @date 2021-03-28 10:53:06
 */
@Repository
public interface BrandMapper extends BaseMapper<Brand, Long> {

    /**
     * description: 新增一条分类品牌中间表数据信息
     * @author 朱正磊
     * @date 2021-03-29 00:03:53
     * @param cid 商品分类id
     * @param bid 品牌id
     * @return 返回新增状态
     */
    @Insert("insert into tb_category_brand (category_id, brand_id) values (#{cid}, #{bid})")
    Integer insertCategoryBrand(@Param("cid") Long cid, @Param("bid") Long bid);

    /**
     * description: 根据分类id查询品牌集合
     * @author 朱正磊
     * @date 2021-04-02 14:21:45
     * @param cid 分类id
     * @return 返回品牌集合
     */
    @Select("select b.* from tb_category_brand cb inner join tb_brand b on cb.brand_id = b.id where cb.category_id = #{cid}")
    List<Brand> queryByCategoryId(@Param("cid") Long cid);

}
